#include "math_3d.h"
#define GLEW_STATIC 1
#include <GL/glew.h>
#include <glut.h>
#include "glwindow.h"
#include "shader.hpp"
#include "config.h"


static GLuint vertexBufferId;
static GLuint colorBufferId;


static GLfloat positions[] = {
	0.0f, -1.0f,-0.9f,
	1.0f, 1.0f,0.9f,
	-1.0f, 1.0f,0.9f,

	0.0f, 1.0f,-0.0f,
	-1.0f, -1.0f,-0.0f,
	1.0f, -1.0f,-0.0f,
};


static GLfloat colors[] = {
	1.0f, 0.0f,0.0f,
	1.0f, 0.0f,0.0f,
	1.0f, 0.0f,0.0f,
	
	0.0f,1.0f,0.0f,   // Color
	0.0f,1.0f,0.0f,   // Color
	0.0f,1.0f,0.0f,   // Color
};




static void OnInitScene(void)
{
	glGenBuffers(1,&vertexBufferId);
	glBindBuffer(GL_ARRAY_BUFFER,vertexBufferId);
    glBufferData(GL_ARRAY_BUFFER,sizeof(positions),positions,GL_STATIC_DRAW);
	glEnableVertexAttribArray(0);
	glVertexAttribPointer(0,3,GL_FLOAT,GL_FALSE,0,0);
 
	glGenBuffers(1,&colorBufferId);
	glBindBuffer(GL_ARRAY_BUFFER,colorBufferId);
    glBufferData(GL_ARRAY_BUFFER,sizeof(colors),colors,GL_STATIC_DRAW);
	glEnableVertexAttribArray(1);
	glVertexAttribPointer(1,3,GL_FLOAT,GL_FALSE,0,0);
 
	
	GLuint program = LoadShaders("shaders\\basic.vs","shaders\\basic.fs");
	glUseProgram(program);
	
}

static void OnReshapeWindow(int width,int height)
{
	glViewport(0,0,width,height);
}

static void OnUpdateScene(float time)
{
//	printf("Update %f\n",time);
}

static void OnRenderScene(void)
{
	glClear(GL_COLOR_BUFFER_BIT);
	
	glClearColor(0.0f, 0.0f, 0.0f, 1.0f);

    glDrawArrays(GL_TRIANGLES,0,6);
	
    glutSwapBuffers();
}
void AddingColor(int argc, char **argv)
{
	printf("Running AddingColor\n");
	GLWindowCreate(1024,1024);

	SetInitSceneCallBack(OnInitScene);
	SetReshapeWindowCallBack(OnReshapeWindow);
	SetUpdateSceneCallBack(OnUpdateScene);
	SetRenderSceneCallBack(OnRenderScene);

	GLWindowStart();
}


